package com.lambda.demo5.demo5;

import java.util.function.Function;

/**
 * @ClassName Test
 * @Description 把字符串"张三,18"转换为学生对象（学生类同上）
 * @Author Kx
 * @Date 2025/4/2 11:10
 * @Version 1.0
 */
public class Test {
    public static void main(String[] args) {
        String str = "张三,18";

        // 定义Function实现类
        Function<String, Student> function = (str1) -> {
            // 截取字符串中的姓名和年龄
            String[] strArr = str1.split(",");
            String name = strArr[0];
            int age = Integer.parseInt(strArr[1]);

            return new Student(name, age);
        };

        Student student = function.apply(str);

        System.out.println(student.getName() + "-" + student.getAge());
    }
}
